package client;

import java.text.FieldPosition;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Iso8601DateFormat extends SimpleDateFormat {

	public Iso8601DateFormat() {
		super("yyyy-MM-dd'T'HH:mm:ssZ");
	}

	@Override
	public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos) {
		StringBuffer format = super.format(date, toAppendTo, pos);
		// format.replace(format.length() - 3, format.length() - 2, "");
		// Server configuration
		format.replace(format.length() - 4, format.length() - 2, "01");
		format.insert(format.length() - 2, ":");
		return format;
	}

	@Override
	public Date parse(String source) throws ParseException {
		source = source.substring(0, source.length() - 3) + source.substring(source.length() - 2, source.length());
		return super.parse(source);
	}

}
